Conditions | 5 |
Total Lines | 68 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import React from "react"; |
||
5 | |||
6 | export default function ZoneModal({navigation, zone, zoneModalVisible, setZoneModalVisible, currentCity}) { |
||
7 | const [zoneType, setZoneType] = useState(null); |
||
8 | const [taxRates, setTaxRates] = useState(null); |
||
9 | const [zoneText, setZoneText] = useState(null); |
||
10 | |||
11 | |||
12 | |||
13 | useEffect(() => { |
||
14 | function getZoneData() { |
||
15 | if (zone) { |
||
16 | setZoneType(zone['zoneType']) |
||
17 | setTaxRates(currentCity['taxRates']) |
||
18 | |||
19 | if (taxRates) { |
||
20 | if (taxRates[`${zoneType}Rate`] > 0) { |
||
21 | setZoneText(`Parking here will cost ${taxRates[`${zoneType}Rate`]}kr`) |
||
22 | } else { |
||
23 | setZoneText(`Park here to reduce ${taxRates[`${zoneType}Rate`]}kr from your trip`) |
||
24 | } |
||
25 | } |
||
26 | |||
27 | } |
||
28 | } |
||
29 | getZoneData(); |
||
30 | }); |
||
31 | |||
32 | |||
33 | |||
34 | return ( |
||
35 | <GestureRecognizer |
||
36 | style={{flex: 1}} |
||
37 | onSwipeDown={ () => setZoneModalVisible(false) } |
||
38 | > |
||
39 | <Modal |
||
40 | animationType="slide" |
||
41 | transparent={true} |
||
42 | visible={zoneModalVisible} |
||
43 | onRequestClose={() => { |
||
44 | setZoneModalVisible(!zoneModalVisible) |
||
45 | }} |
||
46 | |||
47 | > |
||
48 | <View style={styles.modalContainer}></View> |
||
49 | |||
50 | |||
51 | <View style={styles.modalMessage}> |
||
52 | <View style={styles.swipeButton}></View> |
||
53 | |||
54 | <View style={styles.titleContainer}> |
||
55 | <View style={styles.textContainer}> |
||
56 | </View> |
||
57 | |||
58 | </View> |
||
59 | |||
60 | <Text style={{color: 'grey'}}> {zoneType}: {zoneText}</Text> |
||
61 | |||
62 | <Pressable |
||
63 | style={styles.tourButton} |
||
64 | onPress={() => setZoneModalVisible(false)} |
||
65 | > |
||
66 | <Text style={{color: 'white', fontWeight: 'bold'}}>OK</Text> |
||
67 | </Pressable> |
||
68 | |||
69 | |||
70 | </View> |
||
71 | </Modal> |
||
72 | </GestureRecognizer> |
||
73 | ) |
||
136 | }) |